<template>
	<view class="">
		<view :style="{height:windowHeight}">
			<view v-for="(item,index) in caseList" :key="index">
				<view class="case-view" :style="index!=0 ? 'margin-top: 24rpx;':''">
					<view @click="selCase(item,index)" style="height: 236rpx;width: 80rpx;display: flex;align-items: center;justify-content: center;">
						<image :src="item.isSel ? checkBox1:checkBox2" style="width: 24rpx;height: 24rpx;"></image>
					</view>
					<view style="width: 638rpx;">
						<view style="height: 20rpx;"></view>
						<view style="display: flex;align-items: center;">
							<image src="../../../../static/phone/phone_case_list_img.png" 
							style="width: 48rpx;height: 48rpx;"></image>
							<text class="case-view-top-t1">{{item.custName}}</text>
							<text class="case-view-top-t1 case-view-top-t2">编号: {{item.no}}</text>
						</view>
						
						<view class="case-view-top-t3">
							{{item.content}}
						</view>
						
						<view style="display: flex;align-items: center;margin-top: 16rpx;">
							<text class="case-view-top-t1" style="margin-left: 0rpx;">状态：</text>
							<text class="case-view-top-t1" style="color: #2DA9C5;">{{item.status.code=='4' ? item.bizStatus : item.status.desc}}</text>
						</view>
					</view>
					
				</view>
			</view>
			<view style="height: 180rpx;"></view>
		</view>
		
		
		
		
		<view class="view-bottom">
			<view class="view-bottom-s">
				<view class="view-bottom-b" @click="getIt">
					确定
				</view>
			</view>
			
		</view>
	</view>
</template>

<script>
	let app = ''
	export default{
		data(){
			return{
				role:'',
				roleUrl:'',
				
				windowHeight:0,
				needAdapt: false, //判断是不是苹果x以上机型
				page:1,
				caseList:[],
				
				checkBox1:'../../../../static/phone/case-yes.png',
				checkBox2:'../../../../static/phone/case-no.png',
				
				tabIndex:-1,
			}
		},
		onLoad() {
			app = getApp()
			var _this = this
			_this.role = app.globalData.role
			_this.roleUrl =  _this.$roleUrl({tab:_this.role})
			
			_this.needAdapt = app.globalData.needAdapt && app.globalData.isIPhone
			if(_this.needAdapt){
				_this.windowHeight = (app.globalData.windowHeight -88)*2 + 'rpx'
			}else{
				_this.windowHeight = (app.globalData.windowHeight -54)*2 + 'rpx'
			}
			this.getList()
		},
		onShow() {
			
		},
		mounted() {
			
		},
		onPullDownRefresh(){
			console.log('下拉刷新')
			// this.page = 1
			// this.noticeList = []
			this.getList()
		},
		onReachBottom() {
			// console.log('底部')
			// this.page = this.page+1
			// this.getList()
		},
		methods:{
			async getList(){
				
				let _this = this
				uni.showToast({
					title:'正在查询...',
					icon:'loading'
				})
				const res = await _this.$myRequest({
					url:`/${_this.roleUrl}/case/selector/`,
					method:'POST',
					data:{
						page:1,
						size:1000
					}
				})
				uni.hideLoading()
				console.log('案件列表',res)
				if(res.data.code==200){
					_this.caseList = []
					let list = res.data.data
					for (var i = 0; i < list.length; i++) {
						list[i]['isSel'] = false
						_this.caseList.push(list[i])
					}
				}else{
					uni.showToast({
						title:'查询失败，请下拉重试!',
						icon:"error"
					})
				}
			},
			
			selCase(item,index){
				let _this = this
				if(_this.caseList[index]['isSel']){
					_this.caseList[index]['isSel'] = !_this.caseList[index]['isSel']
					_this.tabIndex = -1
				}else{
					for (var i = 0; i < _this.caseList.length; i++) {
						if(index===i){
							_this.caseList[i]['isSel'] = true
							_this.tabIndex = index
						}else{
							_this.caseList[i]['isSel'] = false
						}
					}
				}
				
			},
			
			/**
			 * 拿到数据返回
			 */
			getIt(){
				let _this = this
				if(_this.tabIndex == -1){
					uni.showToast({
						title:'请选择所属案件',
						icon:"none",
						duration:1500
					})
					
				}else{
					//保存数据 返回
					let item = _this.caseList[_this.tabIndex]
					uni.setStorageSync("caseBelongs",item)
					uni.navigateBack({
						delta:-1
					})
				}
			},
		}
	}
</script>

<style>
	page{
		background-color: #f7f7f7;
	}
</style>

<style scoped lang="scss">
	.view-bottom{
		position: fixed;
		width: 100%;
		bottom: 0;
		background-color: #ffffff;
		border-top: 1rpx solid #e1e1e1;
		padding-bottom: env(safe-area-inset-bottom); // 适配iphoneX的底部
	}
	.view-bottom-s{
		height: 108rpx;
		display: flex;
		align-items: center;
	}
	.view-bottom-b{
		width: 686rpx;
		height: 88rpx;
		background: #2DA9C5;
		border-radius: 58rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 36rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: #E8F7FB;
		line-height: 50rpx;
		margin-left: 32rpx;
	}	
	
	.case-view{
		// height: 236rpx;
		min-height: 236rpx;
		background-color: #ffffff;
		display: flex;
		align-items: center;
		
	}
	
	.case-view-top-t1{
		margin-left: 12rpx;
		font-size: 24rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #333333;
		
	}
	.case-view-top-t2{
		color: #999999;
		margin-left: auto;
	}
	.case-view-top-t3{
		margin-top: 20rpx;
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #333333;
		line-height: 40rpx;
	}
</style>